<?php

/**
 * Class cash 提现管理
 */
Class cash_promotionControl extends BaseSellerControl{

    /**
     * 提现管理列表
     */
     public function indexOp(){
         $condition = array();
         if($_GET['state']){
                $condition['state'] = $_GET['state'];
         }else{
                $condition['state'] = 0;
         }
         if($_GET['name']){
              if(is_numeric($_GET['name'])){
                    $condition['order_sn'] = $_GET['name'];
              }else{
                    $condition['name'] = $_GET['name'];
              }
         }
         $condition['class'] = 2;

         $cash = model("predeposit");
         $cash_list = $cash->getCashList($condition);
         foreach($cash_list as $k => $v){
             $member = Model('member')->getMemberInfoByID($v['member_id']);
             $cash_list[$k]['member_name'] = $member['member_name'];
         }
         Tpl::output('class',2);
         Tpl::output('list',$cash_list);
         Tpl::output('show_page',$cash->showpage());
         Tpl::showpage('cash_index');
     }
    /**
     * 提现编辑
     */
    public function editOp(){
        $where['id'] = intval($_GET['id']);
        $model_pd = Model('cash_withdrawal_apply');
        $info = $model_pd->where($where)->find();
        $member = Model('member')->getMemberInfoByID($info['member_id']);
        $info['member_name'] = $member['member_name'];
        Tpl::output('info',$info);
        Tpl::showpage("cash_edit_vb");
    }

    /**
     * 保存编辑
     */
    public function save_editOp(){
        $where['id'] = $_POST['pdc_id'];
        $data['remarks'] = intval($_POST['remark']);
        $data['state'] = 1;
        $class = $_POST['class'];
        $data['verification_time'] = time();
        $cash = model("predeposit");
        $info = $cash->editCash($data,$where);
        if($info){
            $cashinfo = $cash->getCashInfo($where);
            //冻结款清零
            $condition['member_id'] = $_POST['pdc_member_id'];
            $member_info = Model('member')->getMemberInfoByID($_POST['pdc_member_id']);
            $pd_array = [];
            $pd_array['amount'] = $cashinfo['cash'];
            $pd_array['member_id'] = $member_info['member_id'];
            $pd_array['member_name'] = $member_info['member_name'];
            if ($class == 1) {
                $res =  $cash->changePd('fx_store_cash',$pd_array);
            }
            if ($class == 2) {
                $res =  $cash->changePd('fx_hy_cash',$pd_array);
                // 写入代理佣金日志
                $logdata['member_id'] = $_POST['pdc_member_id'];
                $logdata['order_id'] = 0;
                $logdata['tixian_id'] = $cashinfo['id'];
                $logdata['tixian_sn'] = $cashinfo['order_sn'];;
                $logdata['money'] = $cashinfo['cash'];
                $logdata['description'] = "推广提现";
                $logdata['type'] = 2;
                $logdata['addtime'] = time();
                Model()->table('brokerage_log')->insert($logdata);
            }

            if($res){
                if($res){
                    showDialog('操作成功！',  urlShop('cash_promotion','index'),'succ');
                }else{
                    showDialog('操作失败！',  urlShop('cash_promotion','index'));
                }
            }
        }else{
            showDialog('操作失败！',  urlShop('cash_promotion','index'));
        }
    }
}